
/**
 * jQuery Cookie plugin
 *
 * Copyright (c) 2010 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */
jQuery.cookie = function (key, value, options) {

    // key and at least value given, set cookie...
    if (arguments.length > 1 && String(value) !== "[object Object]") {
        options = jQuery.extend({}, options);

        if (value === null || value === undefined) {
            options.expires = -1;
        }

        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }

        value = String(value);

        return (document.cookie = [
            encodeURIComponent(key), '=',
            options.raw ? value : encodeURIComponent(value),
            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
            options.path ? '; path=' + options.path : '',
            options.domain ? '; domain=' + options.domain : '',
            options.secure ? '; secure' : ''
        ].join(''));
    }

    // key and possibly options given, get cookie...
    options = value || {};
    var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};

$(document).ready(function() {



    //Sidebar Accordion Menu:

    $("#main-nav li ul").hide(); // Hide all sub menus
    $("#main-nav li a.current").parent().find("ul").slideToggle("slow"); // Slide down the current menu item's sub menu

    $("#main-nav li a.nav-top-item").click(// When a top menu item is clicked...
            function () {
                $.cookie("menu_el",$(this).attr('id'));
                $(this).parent().siblings().find("ul").slideUp("normal"); // Slide up all sub menus except the one clicked
                $(this).next().slideToggle("normal"); // Slide down the clicked sub menu
                return false;
            }
    );

    $("#main-nav li a.no-submenu").click(// When a menu item with no sub menu is clicked...
            function () {
                window.location.href = (this.href); // Just open the link instead of a sub menu
                return false;
            }
    );

    // Sidebar Accordion Menu Hover Effect:

    $("#main-nav li .nav-top-item").hover(
            function () {
                $(this).stop().animate({ paddingRight: "25px" }, 200);
            },
            function () {
                $(this).stop().animate({ paddingRight: "15px" });
            }
    );

    //Minimize Content Box

    $(".content-box-header h3").css({ "cursor":"s-resize" }); // Give the h3 in Content Box Header a different cursor
    $(".closed-box .content-box-content").hide(); // Hide the content of the header if it has the class "closed"
    $(".closed-box .content-box-tabs").hide(); // Hide the tabs in the header if it has the class "closed"

    $(".content-box-header h3").click(// When the h3 is clicked...
            function () {
                $(this).parent().next().toggle(); // Toggle the Content Box
                $(this).parent().parent().toggleClass("closed-box"); // Toggle the class "closed-box" on the content box
                $(this).parent().find(".content-box-tabs").toggle(); // Toggle the tabs
            }
    );

    // Content box tabs:

    $('.content-box .content-box-content div.tab-content').hide(); // Hide the content divs
//    $('ul.content-box-tabs li a.default-tab').addClass('current'); // Add the class "current" to the default tab
    var el = $('#'+$.cookie("menu_el"));
    $('#'+$.cookie("menu_el")).addClass('current').parent().show();
    el.parent().siblings().find("ul").slideUp("normal"); // Slide up all sub menus except the one clicked
    el.next().slideToggle("normal"); // Slide down the clicked sub menu
//    $('.content-box-content div.default-tab').show(); // Show the div with class "default-tab"


    $('.content-box ul.content-box-tabs li a').click(// When a tab is clicked...
            function() {
                $(this).parent().siblings().find("a").removeClass('current'); // Remove "current" class from all tabs
                $(this).addClass('current'); // Add class "current" to clicked tab
                var currentTab = $(this).attr('href'); // Set variable "currentTab" to the value of href of clicked tab
                $(currentTab).siblings().hide(); // Hide all content divs
                $(currentTab).show(); // Show the content div with the id equal to the id of clicked tab

                return false;
            }
    );

    //Close button:

    $(".close").click(
            function () {
                $(this).parent().fadeTo(400, 0, function () { // Links with the class "close" will close parent
                    $(this).slideUp(400);
                });
                return false;
            }
    );

    // Alternating table rows:

    $('tbody tr:even').addClass("alt-row"); // Add class "alt-row" to even table rows

    // Check all checkboxes when the one in a table head is checked:

    $('.check-all').click(
            function() {
                $(this).parent().parent().parent().parent().find("input[type='checkbox']").attr('checked', $(this).is(':checked'));
            }
    );

    // Initialise Facebox Modal window:

    $('a[rel*=modal]').facebox(); // Applies modal window to any link with attribute rel="modal"

    // Initialise jQuery WYSIWYG:

    //here are
//    $(".wysiwyg").tinymce({
//
//			// Location of TinyMCE script
//			script_url : '/js/tinymce/jscripts/tiny_mce/tiny_mce.js',
//            height : "480",
//            width : "980",
//			// General options
//			theme : "advanced",
//			plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,advlist",
//
//			// Theme options
//			theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
//			theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
//			theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
//			theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",
//			theme_advanced_toolbar_location : "top",
//			theme_advanced_toolbar_align : "left",
//			theme_advanced_statusbar_location : "bottom",
////			theme_advanced_resizing : true,
//
//			// Example content CSS (should be your site CSS)
////			content_css : "css/content.css",
//			// Replace values for the template plugin
//			template_replace_values : {
//				username : "Some User",
//				staffid : "991234"
//			}
//
//		$(".wysiwyg").wysiwyg({toolbarHtml:true,
//controls: {
//        bold: { visible : true },
//	html: {visible : true}
//    }
//}); // Applies WYSIWYG editor to any textarea with the class "wysiwyg"

    tinyMCE.init({
        mode : "textareas",
        theme : "advanced",
        plugins : "ccSimpleUploader,advimage,advlink,media,contextmenu,table",
        theme_advanced_buttons1_add_before : "newdocument,separator",
        theme_advanced_buttons1_add : "fontselect,fontsizeselect",
        theme_advanced_buttons2_add : "separator,forecolor,backcolor,liststyle",
        theme_advanced_buttons2_add_before: "cut,copy,separator,ccSimpleUploader",
        theme_advanced_buttons3_add_before : "",
        theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        extended_valid_elements : "hr[class|width|size|noshade]",
        paste_use_dialog : false,
        theme_advanced_resizing : true,
        theme_advanced_resize_horizontal : true,
        apply_source_formatting : true,
        force_br_newlines : true,
        force_p_newlines : false,
        relative_urls : false,
        file_browser_callback: "ccSimpleUploader",
        plugin_ccSimpleUploader_upload_path: '/media/upload/',
        plugin_ccSimpleUploader_upload_substitute_path: '/media/upload/'
    });

});
  
  
  
